using System.Linq.Expressions;
using Common.Page;

namespace Domain.Repositories;

/// <summary>
/// 仓储通用接口类
/// </summary>
/// <typeparam name="TEntity">泛型实体类</typeparam>
public interface IBaseRepository<TEntity> where TEntity : class, new()
{
    Task<TEntity?> AddAsync(TEntity? entity);

    Task AddRangeAsync(List<TEntity> entity);
    
    TEntity? Update(TEntity? entity);

    List<TEntity>? UpdateRange(List<TEntity>? entity);

    void DeleteRange(List<TEntity> entities);

    void Delete(TEntity entity);

    Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> where, bool isIncludeDelete = false);

    Task<int> CountAsync(Expression<Func<TEntity, bool>> where, bool isIncludeDelete = false);

    Task<bool> AnyAsync(Expression<Func<TEntity, bool>> where, bool isIncludeDelete = false);

    Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> where, bool isIncludeDelete = false);

    Task<List<TEntity>> GetListAsync<TKey>(Expression<Func<TEntity, bool>> where,Expression<Func<TEntity, TKey>> orderBy, bool isDesc = true, bool isIncludeDelete = false);
        
    Task<PageList<TEntity>> GetPageListAsync<TKey>(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TKey>> orderBy, int pageIndex, int pageSize, bool isDesc = true,bool isIncludeDelete = false);
        
}